<?php
##############################################
#
#   已报名
# @ Time : 2017-2-28 - 下午11:39:25
# @ Author : JiangYongWei <1085562810@qq.com>
# @ Encoding : UTF-8 language : PHP
#
##############################################

namespace Home\Model;

class InfoSetModel extends IndexBaseModel{

	/*活动表  */
	protected $tableName = 'info_set';
	protected $_field = array('id', 'nickname', 'headimgurl', 'add_time');
	
	/**
	 * 获取活动
	 */
	public function getActivity($city, $activity_name){
	    if($activity_name){
	        $map['activity_name'] = array('like','%'.$activity_name.'%');
	    }
	    
	    $map = array('city'=>$city,'is_show_index'=>1, 'trial_status'=>2);
	    $map['type'] =  array(array('eq',1),array('eq',2), 'or') ;
	    $count = $this -> where($map)->count();// 查询满足要求的总记录数
	    $Page = new \Think\Page($count, 1);
	    $show = $Page->show();
	    $result = $this->field($this->_field)->where($map)->order('is_top desc, id desc')->limit($Page->firstRow.','.$Page->listRows)->select();
	    return array($result, $show);
	}
	
	/**
	 * 获取详情
	 */
	public function getActivityDetail($id) {
	    return $this->where("id = $id")->find();
	}
	
	/**
	 * 获取推荐活动
	 */
	public function getRecommend($city) {
	    return $this->field($this->_field)->where("city = '$city' and trial_status = 2")->limit(4)->order('add_time desc')->select();
	}
	
	/**
	 * 获取已报名总人数 、 报名列表
	 */
	public function getSignUp($acitvity_id) {
	    $data[0] = $this->where("activity_id = $acitvity_id")->count();
	    $data[1] = $this->where("activity_id = $acitvity_id")->field($this->_field)->order('id desc')->limit(5)->select();
	    return array($data[0], $data[1]);
	}

	/**
	 * 详情页报名用户
	 */
	
	public function getDetailMoreSignUp($activity_id) {
	    $map['activity_id'] = $activity_id;
	    $count = M('activity_order')->where($map)->count();// 查询满足要求的总记录数
	    $Page = new \Think\Page($count, C('listRows'));
	    $show = $Page->show();
	    $fields = array('u.id', 'u.nickname', 'u.headimgurl', 'a.add_time');
	    $result = M('activity_order')
            	    ->alias('a')
            	    ->field($fields)
            	    ->join('__USERS__ u on u.id = a.user_id')
            	    ->where($map)->order('a.id desc')
            	    ->limit($Page->firstRow.','.$Page->listRows)->select();
	    
	    $result1 = M('activity_order')
            	    ->alias('a')
            	    ->field($fields)
            	    ->join('__USERS__ u on u.id = a.user_id')
            	    ->where($map)->order('a.id desc')
            	    ->limit(5)->select();
	    //showData($result);
	    return array($result, $show, $count, $result1);
	}
	
	/**
	 * 已付款报名用户
	 */
	public function getmoreSignUp($activity_id) {
	    $map['activity_id'] = $activity_id;
	    $map['order_status'] = 2;
	    $map['payment_status'] = 2;//已付款
	    $count = M('activity_order')->where($map)->count();// 查询满足要求的总记录数
	    $Page = new \Think\Page($count, 2);
	    $show = $Page->show();
	    $fields = array('u.id', 'a.name', 'u.headimgurl', 'a.add_time', 'a.mobile');
	    $result = M('activity_order')
	              ->alias('a')
	              ->field($fields)
	              ->join('__USERS__ u on u.id = a.user_id')
	              ->where($map)->order('a.id desc')
	              ->limit($Page->firstRow.','.$Page->listRows)->select();
	    //showData($result);
	    return array($result, $show, $count);
	}
	
}
